<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.psnname" placeholder="员工姓名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="findList">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="addCompany">新增</el-button>
        </el-form-item>
        <el-form-item style="float:right">
          <el-switch v-model="isAllowUpdate" active-text="允许修改" inactive-text="不允许修改" @change="changeState"></el-switch>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table
      :data="list"
      highlight-current-row
      v-loading="listLoading"
      style="width: 100%;"
      height="70vh"
    >
      <el-table-column prop="groupname" label="集团" align="center"></el-table-column>
      <el-table-column prop="corptypename" label="公司" align="center"></el-table-column>
      <el-table-column prop="unitname" label="分公司" align="center"></el-table-column>
      <el-table-column prop="psnname" label="员工" align="center"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="handEdit(scope.row)">编辑</el-button>
          <el-button size="small" @click="handDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar">
      <!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
      <el-pagination
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :page-size="10"
        :total="total"
        style="float:right;"
        :current-page="page"
      ></el-pagination>
    </el-col>
    <!--新增 编辑界面-->
    <el-dialog title="采购经理设置" :visible.sync="addFormVisible" :close-on-click-modal="false">
      <addHandle @hideTotas="hideTotas" v-if="addFormVisible" :sendFormData="sendFormData"></addHandle>
    </el-dialog>
  </section>
</template>

<script>
import addHandle from "./components/addHandle";
import {
  wlcPurchasingManagerList,
  wlcPurchasingManagerRemove,
  wlcPurchasingManagerFindIsAllowUpdate,
  wlcPurchasingManagerIsAllowUpdate
} from "../../api/baseSetting";

export default {
  data() {
    return {
      filters: {
        psnname: "",
      },
      addFormVisible: false,
      list: [],
      total: 0,
      page: 1,
      listLoading: false,
      //点中的参数
      sendFormData: {},
      isAllowUpdate:false,
    };
  },
  components: {
    addHandle,
  },
  methods: {
    //点击删除
    handDelete(e) {
      let id = e.id;
      this.$confirm("确认删除该菜单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          wlcPurchasingManagerRemove([{ id }]).then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.filters.psnname = "";
            this.page = 1;
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "fail",
            message: "删除失败!",
          });
          this.page = 1;
          this.filters.psnname = "";
          this.getList();
        });
    },
    //点击编辑
    handEdit(detail) {
      this.sendFormData = detail;
      this.addFormVisible = true;
    },
    //分页
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    //隐藏新增表单
    hideTotas() {
      this.addFormVisible = false;
      this.filters.psnname = "";
      this.page = 1;
      this.getList();
    },
    //点击新增
    addCompany() {
      this.sendFormData = {};
      this.addFormVisible = true;
    },
    //点击查询
    findList() {
      if (this.filters.psnname) {
        this.page = 1;
      }
      this.getList();
    },
    //获取菜单列表
    getList() {
      let pageData = {
        page: {
          page: this.page,
          pageSize: 10,
        },
      };
      let para = Object.assign({}, pageData, this.filters);
      //   let para = {
      //     psnname: this.filters.psnname,
      //     page: {
      //       page: this.page,
      //       pageSize: 10,
      //     },
      //   };
      this.listLoading = true;
      wlcPurchasingManagerList(para)
        .then((res) => {
          this.listLoading = false;
          this.list = res.records;
          this.total = res.total;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    //获取修改订单状态
    getState(){
      wlcPurchasingManagerFindIsAllowUpdate({}).then(res=>{
        console.log(res);
        if(res && res == 1){
          this.isAllowUpdate = true
        }else{
          this.isAllowUpdate = false
        }
      })
    },
    changeState(e){
      let isAllowUpdate = e?1:0;
      wlcPurchasingManagerIsAllowUpdate(isAllowUpdate).then(res=>{
        console.log(res);
      })
    }
  },
  mounted() {
    this.getList();
    this.getState();
  },
};
</script>
<style lang="less" scoped>
</style>
